#!/usr/bin/python
# -*- coding: UTF-8 -*-

from kpautos.engine.case import Case
from kptest.config.enum import DeviceType, HostType, DeviceUtility
from extension.utils import password_generator


class Interface_REDFISH_RULER_001(Case):
    """
        Name:
            Interface_REDFISH_RULER_001
        Label:
            验证redfish接口创建管理员用户
        PreCondition:
            1、BMC正常运行
        TestStep:
            1、发送请求，创建管理员用户
            2、查看响应报文，有结果A）
        ExpectedResult:
            A）请求发送成功，响应报文符合规范
        Parameters:

        Remark:

    """

    # 测试执行前配置等准备操作
    def pre_test_case(self):
        self.device_dut = self.resource.get_device(device_type=DeviceType.Server, utility=DeviceUtility.DUT)
        self.os_host = self.device_dut.get_host(host_type=HostType.HostOS)
        self.cli_api = self.device_dut.get_api(ns_name="Redfish")
        self.new_user_id = None

        # 测试步骤
    def procedure(self):
        self.log_step(" 1、发送请求，创建管理员用户")
        result = self.cli_api.redfish_account_create_user(username="test_user", password=password_generator.gen(), role="Administrator")

        self.log_step(" 2、查看响应报文，有结果A）")
        if result.extend_data.ok:
            self.logger.info("A）请求发送成功，响应报文符合规范")
            self.new_user_id = result.Id


    # 测试结束后恢复环境
    def post_test_case(self):
        if self.new_user_id:
            self.cli_api.redfish_account_delete_user(self.new_user_id)
